package com.cby.android.sample

import android.app.Application
import com.cby.android.library.base.LoadConfigCenter
import com.cby.android.olive.CbyOliveTools
import com.cby.android.sample.model.MetaImageViewModel
import com.cby.android.sample.repository.MetaApi
import com.cby.android.sample.repository.MetaApiImpl
import com.scwang.smart.refresh.footer.BallPulseFooter
import com.scwang.smart.refresh.footer.ClassicsFooter
import com.scwang.smart.refresh.header.ClassicsHeader
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.context.GlobalContext
import org.koin.core.logger.Level
import org.koin.dsl.module


/**
 * @description: App
 * @author: ChenBaoYang
 * @createDate: 2022/4/27 9:36 上午
 */
class App : Application() {

    private val mviAppModule = module {
        single<MetaApi> { MetaApiImpl() }
        viewModel { MetaImageViewModel(this@App) }
    }

    override fun onCreate() {
        super.onCreate()
        initGlobalSmartRefreshLayout()
        LoadConfigCenter.initLoadSirConfig()
        CbyOliveTools.init(this@App)
        GlobalContext.startKoin {
            androidLogger(Level.DEBUG)
            androidContext(androidContext = this@App)
            modules(mviAppModule)
        }
    }

    private fun initGlobalSmartRefreshLayout() {
        //设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreator { context, layout ->
            layout.setPrimaryColorsId(R.color.colorAccent, R.color.white)//全局设置主题颜色
            ClassicsHeader(context)//.setTimeFormat(DynamicTimeFormat("更新于 %s")) //指定为经典Header，默认是 贝塞尔雷达Header
        }
        //设置全局的Footer构建器
        SmartRefreshLayout.setDefaultRefreshFooterCreator { context, layout ->
            layout.setPrimaryColorsId(R.color.colorAccent, R.color.white)//全局设置主题颜色
            ClassicsFooter(context).setDrawableSize(20f)
        }

    }
}